home *** CD-ROM | disk | FTP | other *** search
- > I seem to be stuck on a problem of detecting bob collisions. My
- > problems is that I need to test for so many. I have a total of 12
- > (or slightly more) objects all of which must look out for eachother.
- > Putting the collision detection routine in a loop is far too slow.
- > Basically I have to call the collision detection procedure 100+ times
- > per frame. Is there an ultra fast way to do this? My game is down
- > to about 2 fps. :( Is there any way to do it without getting a
- > special extension?
-
- What sort of design are you using?
- I normally rely on an optimized program-design to achieve the speed
- in my projects, so...
-
- First, you need to set up your procedure _FINDHITNUM as well as
- declare the global for it...
-
- Procedure _FINDHITNUM[FIRST, LAST]
- HITFLAG=False : Rem ...reset collision-flag
- Rem Run through the Col-list to see which Bob was Hit
- For CHECKIT=FIRST To LAST
- If Col(CHECKIT)
- HITFLAG=CHECKIT : Rem ...set flag to ID of object hit
- CHECKIT=LAST : Rem ...my way to exit a loop
- End If
- Next CHECKIT
- End Proc
-
- Global HITFLAG
-
- You have 12 objects which need to collide with any of the other 11,
- so using Bob Col() you can "quickly" see if an object is colliding
- with any of the others...
-
- This can be processed as follows:
-
- For OBJECTNUM=0 to 11
- Rem Is this the first object?
- If OBJECTNUM=0
- Rem yes, so need to check only against all "higher" objects...
- If Bob Col(0, 1 To 11 )
- _FINDHITNUM[1, 11]
- End If
-
- Else
- Rem Is this the last object?
- If OBJECTNUM=11
- Rem yes, so need to check only "lower" objects...
- If Bob Col(11, 0 to 10)
- _FINDHITNUM[0, 10]
- End If
-
- Else
- Rem ObjectToCheck is between lowest and highest, so we
- Rem need to perform two checks...
- Rem One for the objects lower than OBJECTNUM...
- If Bob Col(OBJECTNUM, 0 To OBJECTNUM-1)
- _FINDHITNUM[0, OBJECTNUM-1]
- Else
- Rem and a second for objects higher than OBJECTNUM...
- If Bob Col(OBJECTNUM, OBJECTNUM+1, 11)
- _FINDHITNUM[OBJECTNUM+1, 11]
- End If
- End If
- End If
- End If
-
- Rem This object has been checked, so we analyze the result...
- If HITFLAG
- Rem If here, OBJECTNUM and HITFLAG objects have collided
- Rem so, do your processing...
- End If
- Next OBJECTNUM
-
- This is a reasonably optimized design and AMOS should be able to
- sort out the collisions reasonably fast... :)
-
- Let me know how you make out!!
-
-
- Take care,
- GARFIELD
- _________________________
- Current projects...
- SideShooter(AMOS): 85% Complete
- Website(http://www.sosbbs.com/~gbenjam): 20% Complete
-
-